package com.sr.vo.req;

import com.sr.pojo.WNavBar;
import com.sr.util.ToolUtil;
import com.sr.vo.BaseForm;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Range;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import java.util.Date;

/**
 * @author xiaochi
 * @date 2022/4/27 18:39
 * @desc WNavBar
 */
@Data
@ApiModel("导航实体")
@EqualsAndHashCode(callSuper = true)
public class NavBarReqVo extends BaseForm<WNavBar> {

    @ApiModelProperty("导航id更新时必须")
    @Size(min = 19, max = 19, message = "id长度为{max}位",groups = Update.class)
    @NotBlank(message = "导航名称id不能为空", groups = Update.class)
    private String id;

    @ApiModelProperty("导航名称不能超过16个字符")
    @NotBlank(message = "导航名称不能为空",groups = {Create.class,Update.class})
    @Size(max = 16,message = "名称最大不能超过{max}位",groups = {Create.class,Update.class})
    private String name;

    @ApiModelProperty("导航排序")
    @Range(min = 0,max = 120,message = "导航排序为{min} ~ {max}",groups = {Create.class,Update.class})
    private Integer order;

    @ApiModelProperty("导航是否展示")
    @Range(min = 0,max = 1,message = "导航是否展示值只能{min}或{max}",groups = {Create.class,Select.class,Update.class})
    private Integer isShow;

    @Override
    public WNavBar buildEntity() {
        WNavBar wNavBar = ToolUtil.copy(this, WNavBar.class);
        Date date = new Date();
        if (StringUtils.isEmpty(wNavBar.getId())) {
            wNavBar.setId(ToolUtil.nextId());
            wNavBar.setCreateTime(date);
            wNavBar.setUpdateTime(date);
        } else {
            wNavBar.setUpdateTime(date);
        }
        return wNavBar;
    }
}
